﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="UserList.aspx.cs" Inherits="SBACN.WebSite.Admin.Systems.UserList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
	<script type="text/javascript" src="/js/plugin/jquery.blockUI.js"></script>
	<script type="text/javascript">
		function ShowBlock(reset) {
			$jqy.blockUI({
				message: document.getElementById('div_Content'),
				css: {
					top: '50%',
					left: '50%',
					textAlign: 'left',
					marginLeft: (-($jqy(document.getElementById('div_Content')).width() / 2)) + 'px',
					marginTop: (-($jqy(document.getElementById('div_Content')).height() / 1.5)) + 'px',
					width: ($jqy(document.getElementById('div_Content')).width() + 10) + 'px',
					hight: $jqy(document.getElementById('div_Content')).height() + 'px'
				}
			});
			if (reset) {
				document.getElementById("<%= hid_UserName.ClientID%>").value = "";
				document.getElementById("<%= txt_Name.ClientID%>").value = "";
				document.getElementById("<%= txt_NickName.ClientID%>").value = "";
				document.getElementById("<%= txt_EMail.ClientID%>").value = "";
				document.getElementById("<%= ddl_Member.ClientID%>").value = "0";
				document.getElementById("<%= ddl_Role.ClientID%>").value = ""
				var status = document.getElementById("<%= rbl_Status.ClientID%>").getElementsByTagName("input");
				for (var i = 0; i < status.length; i++) {
					if (status[i].type == "radio") {
						status[i].checked = (status[i].value == "1");
					}
				}
				document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "";
				$jqy("#<%= txt_Name.ClientID%>").removeAttr("disabled");
			}
		}

		function GetUser(userName) {
			$jqy.get("<%= RootPath%>Handler/Admin/RoleHandler.ashx?un=" + userName, function (data) {
				$jqy("#<%= txt_Name.ClientID%>").attr("disabled", "true");
				document.getElementById("<%= hid_UserName.ClientID%>").value = data.Name; 
				document.getElementById("<%= txt_Name.ClientID%>").value = data.Name;
				document.getElementById("<%= txt_NickName.ClientID%>").value = data.NickName;
				document.getElementById("<%= txt_EMail.ClientID%>").value = data.EMail;
				document.getElementById("<%= ddl_Member.ClientID%>").value = data.MemberID;
				document.getElementById("<%= ddl_Role.ClientID%>").value = data.RoleID;
				var status = document.getElementById("<%= rbl_Status.ClientID%>").getElementsByTagName("input");
				for (var i = 0; i < status.length; i++) {
					if (status[i].type == "radio") {
						status[i].checked = (status[i].value == (data.Status.toString().toLowerCase() == "true" ? "1" : "0"));
					}
				}
				document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "";
				ShowBlock(false);
			});
		}

		function validInput() {
			var username_Hide = $jqy.trim(document.getElementById("<%= hid_UserName.ClientID%>").value);
			var username = $jqy.trim(document.getElementById("<%= txt_Name.ClientID%>").value);
			var nickname = $jqy.trim(document.getElementById("<%= txt_NickName.ClientID%>").value);
			var email = $jqy.trim(document.getElementById("<%= txt_EMail.ClientID%>").value);
			var memberid = $jqy.trim(document.getElementById("<%= ddl_Member.ClientID%>").value);
			var roleid = $jqy.trim(document.getElementById("<%= ddl_Role.ClientID%>").value);

			if (username.length == 0 && username_Hide.length == 0) {
				document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "用户名不能为空!";
				return false;
			}
			if (email.length == 0 || !(email.lastIndexOf(".") > (email.indexOf("@") + 1) && email.indexOf("@") > 1 && email.lastIndexOf(".") < email.length - 2)) {
				document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "邮件地址不能为空或邮件地址不正确!";
				return false;
			}
			if (!$jqy.isNumeric(roleid)) {
				document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "必须选择权限角色!";
				return false;
			}

			$jqy("#div_Content").hide();
			document.getElementById("<%= lbl_Msg.ClientID%>").innerText = "";
			document.getElementById('form1').appendChild(document.getElementById('div_Content'));
			return true;
		}

		function ResetPwd(name) {
			if ($jqy.trim(name).length > 0 && confirm("请确认是否重置此用户的密码?")) {
				document.getElementById("<%= hid_UserName.ClientID%>").value = name;
				document.getElementById("<%= btn_ResetPwd.ClientID%>").click();
			}
		}

		function HideBlock() {
			$jqy.unblockUI();
		}

		function ChangeUserStatus(name) {
			if ($jqy.trim(name).length > 0) {
				document.getElementById("<%= hid_UserName.ClientID%>").value = name;
				document.getElementById("<%= btn_Delete.ClientID%>").click();
			}
		}
		function UserSearch() {
			var keywords = $jqy.trim(document.getElementById("<%= txt_UserKeyWords.ClientID%>").value);
			//if (keywords.length > 0) {
				document.getElementById("<%= txt_UserKeyWords.ClientID%>").value = keywords;
				return true;
			//}
			//return false;
		}
	</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table-stroke2">
		<tr align="center">
			<td class="form-body">
				搜索关键字:
				<input type="text" id="txt_UserKeyWords" value="" runat="server" clientidmode="Static" />
				<asp:Button ID="btn_Search" CssClass="btnsearch" Text=" 搜 索 " runat="server" OnClientClick="return UserSearch();" OnClick="btn_Search_Click" />
			</td>
		</tr>
	</table>
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table-stroke2">
		<tr>
			<td class="form-title2" width="10%">
				登录名
			</td>
			<td class="form-title2" width="10%">
				姓名
			</td>
			<td class="form-title2" width="10%">
				角色
			</td>
			<td class="form-title2" width="14%">
				用户分类
			</td>
			<td class="form-title2" width="7%">
				登录时间
			</td>
			<td class="form-title2" width="7%">
				登录IP
			</td>
			<td class="form-title2" width="4%">
				状态
			</td>
			<td class="form-title2" width="13%">
				操作
			</td>
		</tr>
<asp:Repeater ID="rpt_User" runat="server" EnableViewState="false">
	<ItemTemplate>
		<tr>
			<td class="form-body">
				<%# Eval("UserName")%>
			</td>
			<td class="form-body">
				<%# Eval("NickName")%>
			</td>
			<td class="form-body">
				<%# GetRoleName(Eval("UserName").ToString())%>
			</td>
			<td class="form-body">
				<%# GetMemberName(Eval("MemberID"))%>
			</td>
			<td class="form-body">
				<%# Convert.ToDateTime(Eval("LoginTime")).ToString("yyyy-MM-dd") == "0001-01-01" ? "" : Convert.ToDateTime(Eval("LoginTime")).ToString("yyyy-MM-dd")%>
			</td>
			<td class="form-body">
				<%# Eval("LoginIP")%>
			</td>
			<td class="form-body">
				<%# Convert.ToBoolean(Eval("Status")) ? "启用" : "<font color='red'>停用</font>"%>
			</td>
			<td class="form-body">
				<a href="javascript:void(0)" onclick="return GetUser('<%# Eval("UserName")%>');">修改信息</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="return ResetPwd('<%# Eval("UserName")%>');">重置密码</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="return ChangeUserStatus('<%# Eval("UserName")%>');"><%# Convert.ToBoolean(Eval("Status")) ? "停用" : "启用"%></a>
			</td>
		</tr>
	</ItemTemplate>
	<AlternatingItemTemplate>
		<tr style="background-color: #ccc">
			<td class="form-label">
				<%# Eval("UserName")%>
			</td>
			<td class="form-label">
				<%# Eval("NickName")%>
			</td>
			<td class="form-label">
				<%# GetRoleName(Eval("UserName").ToString())%>
			</td>
			<td class="form-label">
				<%# GetMemberName(Eval("MemberID"))%>
			</td>
			<td class="form-label">
				<%# Convert.ToDateTime(Eval("LoginTime")).ToString("yyyy-MM-dd") == "0001-01-01" ? "" : Convert.ToDateTime(Eval("LoginTime")).ToString("yyyy-MM-dd")%>
			</td>
			<td class="form-label">
				<%# Eval("LoginIP")%>
			</td>
			<td class="form-label">
				<%# Convert.ToBoolean(Eval("Status")) ? "启用" : "<font color='red'>停用</font>"%>
			</td>
			<td class="form-label">
				<a href="javascript:void(0)" onclick="return GetUser('<%# Eval("UserName")%>');">修改信息</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="return ResetPwd('<%# Eval("UserName")%>');">重置密码</a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="return ChangeUserStatus('<%# Eval("UserName")%>');"><%# Convert.ToBoolean(Eval("Status")) ? "停用" : "启用"%></a>
			</td>
		</tr>
	</AlternatingItemTemplate>
</asp:Repeater>
		<tr>
			<td colspan="8" class="form-body">
				<asp:Label ID="lbl_MainMsg" runat="server" ForeColor="Red">&nbsp;</asp:Label>
			</td>
		</tr>
		<tr>
			<td colspan="8" class="form-body">
				<input class="btnsearch" type="button" value="新增" onclick="return ShowBlock(true);" />
			</td>
		</tr>
	</table>
	<div id="div_Content" style="display: none; overflow: hidden; padding: 5px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table-stroke2">
			<tr>
				<td colspan="2" class="form-title2">
				</td>
			</tr>
			<tr>
				<td width="20%" class="form-label-1">
					登录名:
				</td>
				<td class="form-body-1">
					<asp:TextBox ID="txt_Name" runat="server" Width="200px" MaxLength="50"></asp:TextBox><span
						style="color: Red">*</span>
				</td>
			</tr>
			<tr>
				<td width="20%" class="form-label-1">
					姓名:
				</td>
				<td class="form-body-1">
					<asp:TextBox ID="txt_NickName" runat="server" Width="200px" MaxLength="50"></asp:TextBox>
				</td>
			</tr>
			<tr>
				<td width="20%" class="form-label-1">
					邮箱:
				</td>
				<td class="form-body-1">
					<asp:TextBox ID="txt_EMail" runat="server" Width="200px" MaxLength="50"></asp:TextBox><span
						style="color: Red">*</span>
				</td>
			</tr>
			<tr>
				<td width="20%" class="form-label-1">
					用户分类:
				</td>
				<td class="form-body-1">
					<asp:DropDownList ID="ddl_Member" runat="server" Width="201px">
						<asp:ListItem Text="后台系统用户" Value="-1"></asp:ListItem>
					</asp:DropDownList>
				</td>
			</tr>
			<tr>
				<td width="20%" class="form-label-1">
					权限角色:
				</td>
				<td class="form-body-1">
					<asp:DropDownList ID="ddl_Role" runat="server" Width="201px">
						<asp:ListItem Text="--请选择--" Value=""></asp:ListItem>
					</asp:DropDownList>
					<span style="color: Red">*</span>
				</td>
			</tr>
			<tr>
				<td width="20%" class="form-label-1">
					状态:
				</td>
				<td class="form-body-1">
					<asp:RadioButtonList ID="rbl_Status" runat="server" RepeatDirection="Horizontal"
						RepeatColumns="5">
						<asp:ListItem Text="启用" Value="1" Selected></asp:ListItem>
						<asp:ListItem Text="禁用" Value="0"></asp:ListItem>
					</asp:RadioButtonList>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="form-body-1">
					<asp:Label ID="lbl_Msg" ForeColor="Red" runat="server">&nbsp;</asp:Label>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="form-body">
					<asp:Button ID="btn_Create" Text="确定"  CssClass="btnsearch" runat="server" OnClientClick="return validInput();"
						OnClick="btn_Create_Click" />&nbsp;
					<input type="button" value="取消"  class="btnsearch" onclick="return HideBlock();" />
				</td>
			</tr>
		</table>
	</div>
	<div style="display: none;">
		<asp:HiddenField ID="hid_UserName" runat="server" Value="" />
		<asp:HiddenField ID="hid_RightList" runat="server" Value="" />
		<asp:Button ID="btn_Delete" Text="修改用户状态"  runat="server" OnClick="btn_Delete_Click" />
		<asp:Button ID="btn_ResetPwd" Text="重置密码"  runat="server" OnClick="btn_RestPwd_Click" />
	</div>
</asp:Content>